﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Drawing;

namespace Dycox.Windows.Forms
{
    public class EllipseLabel : Label
    {
        public EllipseLabel()
        {
            base.AutoSize = false;
            base.TextAlign = ContentAlignment.MiddleCenter;
            base.SetStyle(ControlStyles.UserPaint, true);
        }

        [Browsable(false), DefaultValue(false)]
        public override bool AutoSize
        {
            get
            {
                return false;
            }
            set
            {
                //base.AutoSize = value;
            }
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(this.ClientRectangle);

            this.Region = new System.Drawing.Region(path);

            path.Dispose();
        }

        protected override System.Drawing.Size DefaultSize
        {
            get
            {
                return new System.Drawing.Size(20, 20);
            }
        }

        [DefaultValue(typeof(ContentAlignment), "MiddleCenter")]
        public override ContentAlignment TextAlign
        {
            get
            {
                return base.TextAlign;
            }
            set
            {
                base.TextAlign = value;
            }
        }
    }
}
